#ifndef __GRAPHICALMAP_HPP__
#define __GRAPHICALMAP_HPP__

#include <boost/thread.hpp>

#include "../system/event/EventBase.hpp"

namespace irr
{
    namespace video
    {
        class IVideoDriver;
    }
}

namespace graphicalactors
{
    class GraphicalGenerik;
    class GraphicalSpeedBrick;
    class GraphicalBourik;
    class GraphicalCutit;
}

namespace graphicalenvironment
{

    class GraphicalMap
    {
    private:
        static GraphicalMap* m_Singleton; /// Unique instance of the singleton

        boost::uint8_t m_tabGraphicalSpeedBrickScent[MAP_WIDTH*MAP_HEIGHT];
        boost::uint8_t m_tabGraphicalBourikScent[MAP_WIDTH*MAP_HEIGHT];

        irr::scene::IParticleSystemSceneNode * m_tabGraphicalSpeedBrickScentParticles[MAP_WIDTH*MAP_HEIGHT];
        irr::scene::IParticleSystemSceneNode * m_tabGraphicalBourikScentParticles[MAP_WIDTH*MAP_HEIGHT];

        // vecteur contenant toutes les SPEEDBRICK du jeu
        std::map< int, graphicalactors::GraphicalSpeedBrick * > m_mapGraphicalSpeedBricks; 
        // vecteur contenant toutes les BOURICK du jeu
        std::map< int, graphicalactors::GraphicalBourik * > m_mapGraphicalBouriks;
        // vecteur contenant toutes les CUTIT du jeu
        std::map< int, graphicalactors::GraphicalCutit * > m_mapGraphicalCutits;

        std::vector< irr::core::vector3df >         m_vertexArray;

        // stats 
        int m_createdGraphicalGeneriks;
        int m_aliveGraphicalGeneriks;

        int m_createdGraphicalSpeedBricks;
        int m_aliveGraphicalSpeedBricks;

        int m_createdGraphicalBouriks;
        int m_aliveGraphicalBouriks;

        GraphicalMap();
        virtual ~GraphicalMap();
    public:
        
        /**
        * @fn		getSingletonPtr()
        * @brief	Getter on the singleton
        * @return	The unique instance of the singleton
        */
        static GraphicalMap* getSingletonPtr()
        {
            if (m_Singleton == NULL)
                m_Singleton = new GraphicalMap();
            return m_Singleton;
        }

        /**
        * @fn		getSingleton()
        * @brief	Getter on the singleton
        * @return	The unique instance of the singleton
        */
        static GraphicalMap& getSingleton()
        {
            if (m_Singleton == NULL)
                m_Singleton = new GraphicalMap();
            return *m_Singleton;
        }

        /**
        * @fn		createSingleton()
        * @brief	Create the singleton
        * @return	The unique instance of the singleton
        */
        static GraphicalMap* createSingleton()
        {
            if (m_Singleton == NULL)
                m_Singleton = new GraphicalMap();
            return m_Singleton;
        }

        /**
        * @fn		destroySingleton()
        * @brief	Destroy the singleton
        */
        static void destroySingleton()
        {
            if( m_Singleton != NULL )
                delete m_Singleton;
            m_Singleton = NULL;
        }

        void addGraphicalSpeedBrick( graphicalactors::GraphicalSpeedBrick * _speedBrick );
        void addGraphicalBourik( graphicalactors::GraphicalBourik * _bourik );
        void addGraphicalCutit( graphicalactors::GraphicalCutit * _cutit );

        void removeGraphicalSpeedBrick( int _id );
        void removeGraphicalBourik( int _id );

        // fct

        void Init();
        void Update(irr::video::IVideoDriver* _driver);
        void addGraphicalSpeedBrickScent(float _posX, float _posY, int _numToAdd );
        void addGraphicalBourikScent(float _posX, float _posY, int _numToAdd );
        int GetIndexInTab( float _posX, float _posY );

        void onReceiveNeedGenerikAdd(boost::shared_ptr< Event::EventBase > _evt);        
        void onReceiveNeedGenerikRemove(boost::shared_ptr< Event::EventBase > _evt);
        void onReceiveNeedGenerikScentAdd(boost::shared_ptr< Event::EventBase > _evt);
        //void onReceiveNeedGenerikScentRemove(boost::shared_ptr< Event::EventBase > _evt);
    };

}   //  namespace graphicalenvironment

#endif //__GRAPHICALMAP_HPP__
